﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZOVNP.Model.Abstracts;

namespace ZOVNP.WinView
{
    public partial class PriceEditControl : UserControl
    {
        private IPrice _price;

        public PriceEditControl(IPrice price)
        {
            Price = price;
            InitializeComponent();
        }

        public IPrice Price
        {
            get { return _price; }
            set
            {
                _price = value;

                tbxName.Text = _price != null ? _price.Name : string.Empty;
                tbxDescription.Text = _price != null ? _price.Description : string.Empty;
            }
        }

        private void tbxName_TextChanged(object sender, EventArgs e)
        {
            if (_price == null)
                throw new InvalidOperationException();

            _price.Name = tbxName.Text;
        }

        private void tbxDescription_TextChanged(object sender, EventArgs e)
        {
            if (_price == null)
                throw new InvalidOperationException();

            _price.Description = tbxDescription.Text;
        }
    }
}
